package cn.stylefeng.guns.modular.project.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;

import cn.stylefeng.guns.modular.project.entity.ProjectMember;
import cn.stylefeng.guns.modular.project.model.params.ProjectMemberParam;
import cn.stylefeng.guns.modular.project.service.ProjectMemberService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 控制器
 *
 * @author
 * @Date 2019-10-15 14:06:47
 */
@Controller
@RequestMapping("/project/member")
public class ProjectMemberController extends BaseController {

    private String PREFIX = "/project";

    @Autowired
    private ProjectMemberService projectMemberService;
    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("")
    public String index(Integer projectId) {
        super.setAttr("projectId", projectId);
        return PREFIX + "/projectMember.html";
    }

    /**
     * 新增页面
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/add")
    public String add(Integer projectId) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.orderByAsc("name");
        List<User> list = userService.list(queryWrapper);
        setAttr("users", list);
        setAttr("projectId", projectId);
        return PREFIX + "/projectMember_add.html";
    }

    /**
     * 编辑页面
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/projectMember_edit.html";
    }

    /**
     * 新增接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ProjectMemberParam projectMemberParam) {
        this.projectMemberService.add(projectMemberParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ProjectMemberParam projectMemberParam) {
        this.projectMemberService.update(projectMemberParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ProjectMemberParam projectMemberParam) {
        this.projectMemberService.delete(projectMemberParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ProjectMemberParam projectMemberParam) {
        ProjectMember detail = this.projectMemberService.getById(projectMemberParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author
     * @Date 2019-10-15
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ProjectMemberParam projectMemberParam) {
        return this.projectMemberService.findPageBySpec(projectMemberParam);
    }

}


